﻿Module AllFunctions
    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Long
    Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFilename As String) As Long
    '--------------------------------写入读取注册表自定义函数-----------------------
    '
    Public Function WriteOneString(ByVal section As String, ByVal key As String, ByVal value As String, ByVal filename As String) As Long
        Dim X As Boolean
        Dim Nbuff As New String(CType(" ", Char), 1000)
        Nbuff = value + Chr(0)
        X = WritePrivateProfileString(section, key, Nbuff, filename)
        WriteOneString = X
    End Function

    Public Function ReadOneString(ByVal section As String, ByVal key As String, ByVal Filename As String) As String
        Dim X As Long, i As Integer

        Dim Buffer As New String(CType(" ", Char), 1000)
        X = GetPrivateProfileString(section, key, "", Buffer, 1000, Filename)
        i = InStr(Buffer, Chr(0))
        ReadOneString = Trim(Left(Buffer, i - 1))
    End Function

    Sub DelBlankRow()
        '//删除代码中的多余空行
        Dim aCodePane As VBIDE.CodePane
        Dim aLineNumber As Int32
        Dim aLine As String

        aCodePane = _VBE.ActiveCodePane
        For aLineNumber = _VBE.SelectedVBComponent.CodeModule.CountOfLines To 1 Step -1
            aLine = aCodePane.CodeModule.Lines(aLineNumber, 1)

            If Len(Trim(aLine)) = 0 Then
                _VBE.SelectedVBComponent.CodeModule.DeleteLines(aLineNumber, 1)
            End If

        Next aLineNumber
    End Sub

    ' 注释
    Sub annotation()
        Dim aCodePane As VBIDE.CodePane
        Dim aLineNumber As Int32
        Dim aLine, bLine As String
        Dim StartLine, StartCol, EndLine, EndCol As Long
        _VBE.ActiveCodePane.GetSelection(StartLine, StartCol, EndLine, EndCol)

        ' MsgBox(StartLine & "," & StartCol & "," & EndLine & "," & EndCol)
        aCodePane = _VBE.ActiveCodePane
        For aLineNumber = 1 To aCodePane.CodeModule.CountOfLines
            If aLineNumber >= StartLine And aLineNumber <= EndLine Then
                aLine = aCodePane.CodeModule.Lines(aLineNumber, 1)
                Dim isExitStr As Boolean = InStr(aLine, "'")
                If isExitStr Then
                    bLine = Replace(aLine, "'", "")
                Else
                    bLine = "'" & aLine
                End If

                aCodePane.CodeModule.ReplaceLine(aLineNumber, bLine)
            End If
        Next aLineNumber
    End Sub




End Module
